import cPickle
SAVE_FILE_NAME="progress.txt"
USERS_FILE_NAME="profiles.txt"

def get_users():
	users = []
	try:
		with open(USERS_FILE_NAME, "r") as f:
			users = cPickle.load(f) 
	except IOError:
		should_make_profile = ask_yes_no("No user profiles found; would you " \
			"like to make a new one?")
		if should_make_profile: users.append(make_new_profile())
	
	show_users
			
		
def main():
	tasks_done = []
	
	current_task = str(raw_input("What task do you need to get done? " +
		"(q/quit to exit) "))
	while current_task != "q" and current_task != "quit":
		raw_input("Your current task is: " + current_task + ". Press " +
			"enter when done.")
		 
		tasks_done.append(current_task)
		print("Task complete! So far, you have completed " + 
			str(len(tasks_done)) + " tasks: ")
		show_all(tasks_done)
		
		current_task = str(raw_input("What task do you need to get done " +
			"next?(q/quit to exit) "))
		
	if len(tasks_done) == 0:
		print("You completed nothing.")
	else:
		print("You're awesome! You completed " + str(len(tasks_done)) + 
			" tasks:")
		show_all(tasks_done)
		should_save = ask_yes_no("Do you want to save your progress?")
		if should_save:
			save(tasks_done)
	
def show_all(list_):
	'''Takes in a list of items and displays every item.'''
	
	for item in list_:
		print("\t%s" % item)

def ask_yes_no(question):
	'''Asks a yes/no question. Returns true if the user answers yes and false
	if the user answers no.'''
	
	answer = raw_input(question + "(y/n) ")
	yes_answers = ["y", "yes"]
	no_answers = ["n", "no"]
	valid = yes_answers + no_answers
	while answer not in valid:
		print("What? Answers are " + str(valid) + ".")
		answer = raw_input(question)
	
	if answer in yes_answers:
		return True
	else:
		return False

def save(tasks):
	'''Saves tasks into the save file.'''
	with open(SAVE_FILE_NAME, "a") as f:
		for task in tasks:
			f.write("--" + str(task) + "\n")

if __name__ == "__main__":
	main()

